package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

	@Autowired
	private WmMaterialService wmMaterialService;

	/**
	 * 上传图片接口
	 * @param multipartFile，这个参数的前面传递的默认参数名，别取其他名字
	 * @return
	 */
	@PostMapping("/upload_picture")
	public ResponseResult uploadPicture(MultipartFile multipartFile){
		return wmMaterialService.uploadPicture(multipartFile);
	}

	/**
	 * 素材列表查询
	 * @param dto
	 * @return
	 */
	@PostMapping("/list")
	public ResponseResult findList(@RequestBody WmMaterialDto dto){
		return wmMaterialService.findList(dto);
	}

	//删除接口
	@GetMapping("/del_picture/{id}")
	public ResponseResult delPicture(@PathVariable("id") Integer id) {
		return wmMaterialService.delPicture(id);
	}

	//收藏接口
	@GetMapping("/collect/{id}")
	public ResponseResult collect(@PathVariable("id") Integer id) {
		return wmMaterialService.collectOrCancel(id);
	}

	//取消收藏接口
	@GetMapping("/cancel_collect/{id}")
	public ResponseResult cancelCollect(@PathVariable("id") Integer id) {
		return wmMaterialService.collectOrCancel(id);
	}
}
